<?php
require_once "function.php";
$user=M()->select('user');
 ?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>首页</title>
  <link rel="stylesheet" href="public/semantic.min.css" media="screen" title="no title" charset="utf-8">
  <link rel="stylesheet" href="public/index.css" media="screen" title="no title" charset="utf-8">
</head>
<body>
  <div class="ui container">
    <div class="ui success message hidden">
          <i class="close icon"></i>
      <div class="header">删除成功</div>
    </div>
    <table class="ui celled table">
      <thead>
        <tr>
          <th>ID</th>
          <th>用户名</th>
          <th>邮箱</th>
          <th>电话</th>
          <th>地址</th>
          <th>角色</th>
          <th>管理</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($user as  $v) {
          ?>
        <tr>
          <td><?php echo $v['id'] ?></td>
          <td><?php echo $v['username'] ?></td>
          <td><?php echo $v['email']  ?></td>
          <td><?php echo $v['tel'] ?></td>
          <td><?php echo $v['address'] ?></td>
          <td><?php echo $v['flag']==0?"用户":"管理员" ?></td>
          <td>
            <div class="ui buttons">
              <button class="ui button red del" id="<?php echo $v['id'] ?>">删除</button>
              <div class="or" data-text="or"></div>
              <button class="ui positive button">更改权限</button>
            </div>
          </td>

        </tr>
        <?php
      } ?>
      </tbody>
    </table>
  </div>
  <div class="ui small basic test modal" >
    <div class="ui icon header"><i class="archive icon"></i>确认删除</div>
    <div class="content">
      <p>确认删除？删除之后将不可找回！请谨慎操作！</p>
    </div>
    <div class="actions">
      <div class="ui red basic cancel inverted button"><i class="remove icon"></i> 取消 </div>
      <div class="ui green ok inverted button"><i class="checkmark icon"></i> 确认 </div>
    </div>
  </div>
  <script src="public/jquery-2.2.0.js" charset="utf-8"></script>
  <script src="public/semantic.min.js" charset="utf-8"></script>
  <script type="text/javascript">
    $('.del').click(function(){
      var id=$(this).attr('id');
      var ele=$(this).parents('tr');
      $('.modal').modal({
        onApprove : function() {
          $.post('action.php?c=user&m=del',{id:id},function(data){
            if(data==1){
              ele.remove();
              $('.message').show();
            }else{
                $('.message').removeClass('success');
                $('.message').addClass('negative');
                $('.message .header').html('删除失败');
                $('.message').show();
            }
          });
        }
      }).modal('show');
    })
    $('.message .close').on('click', function() {
    $(this)
      .closest('.message')
      .transition('fade')
    ;
  })
;
  </script>
</body>
</html>
